﻿@page "/gateway/variableruntime"
@namespace ThingsGateway.Gateway.Razor
@using System.Text.Json.Nodes
@using ThingsGateway.Admin.Application
@using ThingsGateway.Admin.Razor
@using ThingsGateway.Gateway.Application
@attribute [Authorize]
@attribute [RolePermission]
@inherits ComponentDefault


<div style="height: var(--table-height);padding: 1px;margin:auto;">

    <AdminTable @ref=table
                TItem="VariableRunTime"
                AutoGenerateColumns="false"
                ShowAdvancedSearch=true
                AllowResizing="true"
                IsFixedHeader=true
                IsMultipleSelect=false
                CustomerSearchModel=CustomerSearchModel
                SearchMode=SearchMode.Top
                ShowExtendButtons=true
                ShowExportButton=false
                ShowExtendDeleteButton=false
                ShowExtendEditButton=false
                ShowDefaultButtons=false
                ExtendButtonColumnWidth=150
                AutoRefreshInterval="10000"
                IsAutoRefresh
                OnQueryAsync="OnQueryAsync"
                IsPagination=true>
        <CustomerSearchTemplate>
            @if (context is VariableSearchInput model)
            {
                @Render(model)
            }
        </CustomerSearchTemplate>
        <TableColumns>
            <TableColumn @bind-Field="@context.DeviceName" ShowTips=true Filterable=true Sortable=true Visible=true />
            <TableColumn @bind-Field="@context.Name" ShowTips=true Filterable=true Sortable=true Visible=true />
            <TableColumn @bind-Field="@context.Description" ShowTips=true Filterable=true Sortable=true Visible=true />
            <TableColumn Field="@context.ChangeTime" ShowTips=true FieldExpression=@(()=>context.ChangeTime) Filterable=true Sortable=true Visible=true />
            <TableColumn Field="@context.CollectTime" ShowTips=true FieldExpression=@(()=>context.CollectTime) Filterable=true Sortable=true Visible=true />
            <TableColumn Field="@context.IsOnline" FieldExpression=@(()=>context.IsOnline) Filterable=true Sortable=true Visible=true />
            <TableColumn Field="@context.LastErrorMessage" ShowTips=true FieldExpression=@(()=>context.LastErrorMessage) Filterable=true Sortable=true Visible=true />

            <TableColumn Field="@context.LastSetValue" FieldExpression=@(()=>context.LastSetValue) Visible=true ShowTips=true Formatter=@(JsonFormatter) />

            <TableColumn Field="@context.RawValue" FieldExpression=@(()=>context.RawValue) Visible=true ShowTips=true Formatter=@(JsonFormatter) />
            <TableColumn Field="@context.Value" FieldExpression=@(()=>context.Value) Visible=true ShowTips=true Formatter=@(JsonFormatter) />


            <TableColumn @bind-Field="@context.DataType" Filterable=true Sortable=true Visible=true />
            <TableColumn @bind-Field="@context.RegisterAddress" Filterable=true Sortable=true Visible=true />

            <TableColumn @bind-Field="@context.ProtectType" Filterable=true Sortable=true Visible="false" />
            <TableColumn @bind-Field="@context.IntervalTime" Filterable=true Sortable=true Visible="false" />
            <TableColumn @bind-Field="@context.OtherMethod" Filterable=true Sortable=true Visible="false" />
            <TableColumn @bind-Field="@context.RpcWriteEnable" Filterable=true Sortable=true Visible="false" />
            <TableColumn @bind-Field="@context.ReadExpressions" Filterable=true Sortable=true Visible="false" />
            <TableColumn @bind-Field="@context.WriteExpressions" Filterable=true Sortable=true Visible="false" />
            <TableColumn @bind-Field="@context.Unit" Filterable=true Sortable=true Visible="false" />

            <TableColumn @bind-Field="@context.Index" Filterable=true Sortable=true Visible="false" />
            <TableColumn @bind-Field="@context.Id" Visible="false" Sortable=true DefaultSort=true DefaultSortOrder="SortOrder.Asc" />
            @* <TableColumn Field="@context.AlarmEnable" FieldExpression=@(()=>context.AlarmEnable) Filterable Sortable="false" Visible="false" />

            <TableColumn @bind-Field="@context.BoolOpenAlarmEnable" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.BoolOpenRestrainExpressions" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.BoolOpenAlarmText" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.BoolCloseAlarmEnable" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.BoolCloseRestrainExpressions" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.BoolCloseAlarmText" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.HAlarmEnable" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.HRestrainExpressions" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.HAlarmText" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.HAlarmCode" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.HHAlarmEnable" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.HHRestrainExpressions" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.HHAlarmText" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.HHAlarmCode" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.LAlarmEnable" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.LRestrainExpressions" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.LAlarmText" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.LAlarmCode" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.LLAlarmEnable" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.LLRestrainExpressions" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.LLAlarmText" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.LLAlarmCode" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.CustomAlarmEnable" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.CustomRestrainExpressions" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.CustomAlarmText" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.CustomAlarmCode" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.Remark1" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.Remark2" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.Remark3" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.Remark4" Filterable Sortable="false" Visible="false" />
            <TableColumn @bind-Field="@context.Remark5" Filterable Sortable="false" Visible="false" />  *@

        </TableColumns>
        <RowButtonTemplate>


            <PopConfirmButton IsDisabled=@(!AuthorizeButton("写入变量")) Size="Size.ExtraSmall" Color="Color.Warning" Icon="fa-solid fa-bars" Text="@Localizer["WriteVariable"]" IsAsync OnConfirm="()=>OnWriteVariable(context)">

                <BodyTemplate>
                    <Textarea @bind-Value=WriteValue ShowLabel="true" ShowLabelTooltip="true" />
                </BodyTemplate>

            </PopConfirmButton>
        </RowButtonTemplate>
    </AdminTable>
</div>
@if (AuthorizeButton("重启"))
{
      <ThingsGateway.Gateway.Razor.QuickActions/>
}
@code {
    AdminTable<VariableRunTime> table;
}
@code {
    RenderFragment Render(VariableSearchInput model) =>

    @<div class="row form-inline g-2">
        <div class="col-12 col-md-6">
            <Select IsVirtualize @bind-Value="model.DeviceId" Items="@CollectDeviceNames" ShowSearch="true" ShowLabel="true" IsClearable DisableItemChangedWhenFirstRender=true  />
        </div>
        <div class="col-12 col-md-6">
            <Select IsVirtualize @bind-Value="model.BusinessDeviceId" Items="@BusinessDeviceNames" ShowSearch="true" ShowLabel="true" IsClearable DisableItemChangedWhenFirstRender=true  />
        </div>
        <div class="col-12 col-md-6">
            <BootstrapInput @bind-Value="model.Name" ShowLabel="true" />
        </div>
        <div class="col-12 col-md-6">
            <BootstrapInput @bind-Value="model.RegisterAddress" ShowLabel="true" />
        </div>
    </div>;

}
